/*
 * Created on Jun 12, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package mygui;


import java.net.URL;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.UIManager;

/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class UIM extends UIManager{

	

	/*!
	 * Path containing the different resources (icons...)
	 */
	private String _resourcePath;

	private ResourceBundle _rb;

	private static UIM _instance = null;

/**
 * Constructor of UIM
 *
 */
	protected UIM()
	{
	super();
	//Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	//_dims = new Rectangle(0, 0, d.width, d.height);

	_resourcePath = "images/";

	try 
		{
		_rb = ResourceBundle.getBundle("resultGUI.Resource");
		}
	catch(MissingResourceException e)
		{
		_rb = null;
		}
	}

	public static UIM getInstance(){
		if(_instance == null)
			_instance = new UIM();
		return _instance;
	}
    


	public String getResourcePath()
	{
		return _resourcePath;
	}

	public void setResourcePath(String s)
	{
		_resourcePath = s;
	}


	public static Object getResourceObject(String name)
	{
	try 
		{
		return getInstance()._rb.getObject(name);
		}
	catch(MissingResourceException e)
		{
		return null;
		}
	}

	public static String getResourceString(String name)
	{
	try 
		{
		return getInstance()._rb.getString(name);
		}
	catch(MissingResourceException e)
		{
		return "";
		}
	}

	public static Icon getResourceIcon(String key)
	{
	Object ob = getResourceObject(key);
	if(ob == null)
		return (Icon)null;
	else if(ob instanceof Icon)
		return (Icon)ob;
	else
		{
		String name = ob.toString();
		if(name.length() == 0)
			return (Icon) getResourceIcon("SMALL_ICON_DEFAULT");
		else
			{
			
		
			String pname = getInstance().getResourcePath();
			if(pname.charAt(pname.length() - 1) != '/')
				pname += "/";
			System.out.println(pname + name);
			
			URL imgURL = UIM.class.getResource(pname + name);
			return new ImageIcon(imgURL);
			}
		}
	}
	

	/**
	 * Creates an imageIcon
	 * @param path the relive path from the class of the file in which the image is.
	 * @param description  
	 * @return an ImageIcon
	 */
		protected static ImageIcon createImageIcon(String path,
												   String description) {
			java.net.URL imgURL = UIM.class.getResource(path);
			if (imgURL != null) {
				return new ImageIcon(imgURL, description);
			} else {
				System.err.println("Couldn't find file: " + path);
				return null;
			}
		}
}
